
package DataStructure.Test;

import DataStructure.linkedlist.*;
import org.junit.Test;
import DataStructure.queue.IntegerQueue;
import DataStructure.queue.Queue;
import DataStructure.stack.IntegerStack;
import DataStructure.stack.Stack;
import DataStructure.tree.BinaryTree;
import DataStructure.tree.Tree;
import DataStructure.tree.TreeNode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MyTest {

    @Test
    public void LinedListTest(){
        int[] val = {1, 2, 3, 4, 5};
        SingleLinkedList singleLinkedList = new SingleLinkedList();
        //初始化
        singleLinkedList.initLinkedList(val);
        System.out.println("初始化结果:");
        singleLinkedList.travelLinkedList();
        //在链尾加入结点
        singleLinkedList.addLast(new ListNode(6));
        System.out.println("在链尾加入结点:");
        singleLinkedList.travelLinkedList();
        //插入结点
        singleLinkedList.insertListNode(new ListNode(10),3);
        System.out.println("插入结点:");
        singleLinkedList.travelLinkedList();
        //删除结点
        singleLinkedList.deleteListNode(3);
        System.out.println("删除结点:");
        singleLinkedList.travelLinkedList();
        //查询结点
        System.out.print("查询结点:");
//        int value = linkedList.inquireListNode(linkedList.getLength());
//        System.out.println(value);
    }

    @Test
    public void QueueTest(){
        Queue queue = new IntegerQueue();
        List<String> list = new ArrayList<>();
        Collections.addAll(list,queue.getQueue().toArray(new String[0]));
    }

    @Test
    public void StackTest(){
        Stack stack = new IntegerStack(10);
        stack.push(5);
        stack.push(4);
        stack.push(3);
        stack.travelStack();
        stack.pop();
        stack.pop();
        stack.travelStack();
    }
    @Test
    public void TreeTest(){
        Integer[] ints = {2, 3, 4, -1, -1, 5, -1, -1, 3, -1, 4, -1, -1};
        List<Integer> list = new ArrayList<>(ints.length);
        Collections.addAll(list,ints);
        Tree binaryTree = new BinaryTree(list);
        TreeNode root = binaryTree.InitTree();
        System.out.println("root="+root.val);
        System.out.println("先序遍历：");
        binaryTree.PreorderTravel(root);
        System.out.println();

        System.out.println("中序遍历");
        binaryTree.InorderTravel(root);
        System.out.println();

        System.out.println("后序遍历：");
        binaryTree.PostorderTravel(root);
    }

    @Test
    public void DoubleLinkedListTest(){
        int[] nums = {1,2,3,4,5,6,7};
        DoubleLinkedList linkedList = new DoubleLinkedList();
        linkedList.initLinkedList(nums);

        linkedList.travelLinkedList();  //1 2 3 4 5 6 7
        linkedList.reverseLinkedList(); //7 6 5 4 3 2 1

        linkedList.addHead(new ListNode(8));//8 1 2 3 4 5 6 7
        linkedList.travelLinkedList();
        linkedList.addLast(new ListNode(9));//8 1 2 3 4 5 6 7  9
        linkedList.travelLinkedList();
        linkedList.insertListNode(new ListNode(10),1);//8 10 1 2 3 4 5 6 7  9
        linkedList.travelLinkedList();
        linkedList.deleteListNode(3);
        linkedList.travelLinkedList();
        linkedList.reverseLinkedList();

    }

    @Test
    public void CircularLinkedListTest(){
        CircularLinkedList linkedList = new CircularLinkedList();
        linkedList.initLinkedList(new int[]{1,2,3,4,5,6,7});
        linkedList.travelLinkedList();

        linkedList.insertListNode(new ListNode(8),0);
        linkedList.insertListNode(new ListNode(9),4);
        linkedList.travelLinkedList();

        linkedList.deleteListNode(7);
        linkedList.travelLinkedList();

        ListNode node = linkedList.inquireListNode(8);
        System.out.println(node.next== linkedList.getHead());
    }

    public static void main(String[] args) {
        System.out.println(String.class);
    }
}
